package cn.com.longfuinfo.wx.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cn.com.longfuinfo.wx.common.FinalParam;

/**
 * 应用服务器启动需要调用微信接口方法
 * 
 * @author Administrator
 * 
 */
public class InitializableServletContextListener implements
		ServletContextListener {

	private final String CONTEXT_PATH = "base";// 根路径名称
	private final String WINXIN_IMAGE_PATH = "weinxin_image_path";// 根路径名称
	//private TokenAPI tokenApi;
	private ServletContext sc;

	public void contextInitialized(ServletContextEvent servletContextEvent) {
		sc = servletContextEvent.getServletContext();
		sc.setAttribute(CONTEXT_PATH, sc.getContextPath());
		sc.setAttribute(WINXIN_IMAGE_PATH, FinalParam.image_path);
		//FinalParam.base = sc.getContextPath();
	/*	java.util.Timer timer = new java.util.Timer(true);
		TimerTask task = new TimerTask() {
			public void run() {
				if (tokenApi == null) {
					tokenApi = new TokenAPI();
				}
				tokenApi = new TokenAPI();
				Token token = tokenApi.token(FinalParam.APPID, FinalParam.APPSECRET);
				FinalParam.setAccess_token(token);
			}
		};
		timer.schedule(task, 0, 7200000);*/
	}

	public void contextDestroyed(ServletContextEvent servletContextEvent) {
	}

}